﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>创建串件单</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
    <style>
        tr,td{border:1px solid;text-align:center;}
        .text_left{text-align:left}
    </style>
</head>
<body style="overflow: hidden;">
    <form id="ExchangeInfoForm">
     <div style="text-align: center;padding-top:20px;">
     <div><div style="width:50%;float:left;padding-left: 30px">编号:<span id="ExchangeName" name="ExchangeName"></span></div><div style="width:50%;float:left;padding-right: 30px">日期:<input class="easyui-datebox ExchangeDate"  name="ExchangeDate" style="width:120px;height:20px"></input></div></div>
     <table  cellspacing="0" style="margin: auto">
         <tr>
            <td colspan="8" class="text_left" style="line-height:30px;padding-left:20px;">
                <input type="checkbox" name="ExchangeMethod" value="0"  id="ExchangeMethod0" onclick="page.checkboxSelect(this)"/><label for="ExchangeMethod0">新机（品）</label>
                <input type="checkbox" name="ExchangeMethod" value="1"  id="ExchangeMethod1" onclick="page.checkboxSelect(this)"/><label for="ExchangeMethod1">修理机（品）</label>
                <div style="width: 160px;float:right;margin-right:200px;">串件类型
                    <select class="easyui-combobox" name="ExchangeType" data-options="panelHeight:'auto'" style="width:100px">
                        <option value="0">串件</option>
		                <option value="1">设计定型</option>
                    </select>
                </div>
            </td>
         </tr>
        <tr>
            <td style="width:105px">新机（品）/</br>修理机（品）编号</td>
            <td style="font-size:28px;"><input class="easyui-textbox" name="ExchangeCodeNo" id="ExchangeCodeNo"/></td>
            <td style="width:70px">任务号</td>
            <td style="width:120px"><input class="easyui-textbox" name="ContainerNo" id="ContainerNo"/></td>
            <td style="width:70px">零组件</br>名称</td>
            <td style="width:120px"><input class="easyui-textbox" id="productContainer" name="ProductID" /></td>
            <td style="width:70px">零组件</br>图号</td>
            <td style="width:120px"><input class="easyui-textbox" name="ProductName" readonly=readonly id="ProductName"/></td>
        </tr>
        <tr>
            <td rowspan="2"  style="width:90px;height:45px">零组件</br>特性</td>
            <td rowspan="2" style="width:100px;">一般件/G/Z</td>
            <td rowspan="2" >零组件</br>批次号</td>
            <td rowspan="2"><input class="easyui-textbox" name="ERPBatchNo" id="ERPBatchNo"/></td>
            <td>已工作时间/</br>总寿命</td>
            <td><input class="easyui-textbox" name="WorkHours"/></td>
            <td rowspan="2">数量</td>
            <td rowspan="2"><input class="easyui-numberbox" name="Qty" /></td>
        </tr>
        <tr>
            <td>厂内工作</br>时间</td>
            <td><input class="easyui-textbox"  name="FactoryWorkHours"/></td>
        </tr>
        <tr>
            <td colspan="8" class="text_left">
                <div >串件原因及处理措施:</div>
                <input class="easyui-textbox" style="width:100%;height:70px;" data-options="multiline:true" name="Reason"/>
            </td>
        </tr>
         <tr>
            <td colspan="8" >
                <div class="text_left">串件零、组件来源:<input class="easyui-textbox" id="productContainer1"  style="width:100%" name="Source"/></div>
            </td>
        </tr>
         <tr>
            <td >新机（品）/</br>修理机（品）编号</td>
            <td colspan="3" style="font-size:28px;" class="text_left"><input id="productContainer2" style="width:100%" name="UpExchangeCodeNo"/></td>
            <td >任务号</td>
            <td ><input class="easyui-textbox" name="UpContainerNo"/></td>
            <td>数量</td>
            <td ><input class="easyui-numberbox" name="UpQty"/></td>
        </tr>
        <tr>
            <td  style="width:90px;height:45px">零组件批次号</td>
            <td  style="width:100px;"><input class="easyui-textbox" name="UpBatchNo"/></td>
            <td>累计工作时</br>间/总寿命</td>
            <td><input class="easyui-textbox" name="TotalWorkHours"/></td>
            <td>厂内工作</br>时间</td>
            <td colspan="3" >
                <div>是否大于被串件厂内工作时间</div>
                    <input type=checkbox name="IsOverFactoryTime" value="1"  id="IsOverFactoryTime1" onclick="page.checkboxSelect1(this)"/><label for="IsOverFactoryTime1">是</label>
                    <input type=checkbox name="IsOverFactoryTime" value="0"  id="IsOverFactoryTime2" onclick="page.checkboxSelect1(this)"/><label for="IsOverFactoryTime2">否</label>
            </td>
        </tr>
     </table> 
      <div style="padding:10px 50px 0 0;text-align:right;"><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.submitData()">确定</a>
      </div>
     </div>
     </form>
     <div id="tb">
        <input class="easyui-searchbox" data-options="prompt:'请输入',searcher:page.InitBigSmallData" style="width:190px">
    </div>
     <div id="tb1">
        <input class="easyui-searchbox" data-options="prompt:'请输入',searcher:page.InitEngineNoData" style="width:190px">
    </div>
     <div id="tb2">
        <input class="easyui-searchbox" data-options="prompt:'请输入',searcher:page.InitEngineNoData1" style="width:190px">
    </div>
     <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/dayjs.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script>
    //创建人：longb
    //日期：2023-05-16
    //描述：创建串件单
    var page = {
        ajaxUrl: getRootPath() + "/Ashx/ZSHandler/ZSExchangeInfoCreateHandler.ashx",
        para: { CId: getParam("CId"), ContainerNo: getParam("ContainerNo"), MachineName: getParam("MachineName"), ExchangeName: getParam("ExchangeName"), ExchangeID: getParam("ExchangeID") },
        init: function () {
            page.bind();
            page.initPageData('');
           
        },
        initPageData: function (type) {
            if (page.para.ExchangeID == "") {
                $('#ExchangeName').html(page.para.ExchangeName);
                $('#ExchangeCodeNo').textbox('setValue', page.para.MachineName);
                $('#ContainerNo').textbox('setText', page.para.ContainerNo).textbox('setValue', page.para.ContainerNo);
                $('.ExchangeDate').datebox('setValue', dayjs().format('YYYY-MM-DD'));
            } else {
                page.post({ action: 'InitData', ExchangeID: page.para.ExchangeID }, false, function (res) {
                    if (res.Result) {
                        $('#ExchangeName').html(res.ReturnData[0].EXCHANGENAME);
                        var data = res.ReturnData[0];
                        var formData = { ExchangeDate: data.CREATEDATE, ExchangeMethod: data.EXCHANGEMETHOD, ExchangeType: data.EXCHANGETYPE, ExchangeCodeNo: data.EXCHANGECODENO, ContainerNo: data.CONTAINERNO,
                            ProductID: data.PRODUCTID, ProductName: data.PRODUCTNAME, ERPBatchNo: data.ERPBATCHNO, FactoryWorkHours: data.FACTORYWORKHOURS,
                            WorkHours: data.WORKHOURS, Qty: data.QTY, Reason: data.REASON,
                            Source: data.BILLSOURCE, UpExchangeCodeNo: data.UPEXCHANGECODENO, UpContainerNo: data.UPCONTAINERNO, UpQty: data.UPQTY, UpBatchNo: data.UPBATCHNO,
                            TotalWorkHours: data.TOTALWORKHOURS, IsOverFactoryTime: data.ISOVERFACTORYTIME
                        }
                        $('#ExchangeInfoForm').form('load', formData);
                    }
                });
            }
        },
        //页面事件绑定
        bind: function () {
            var data = [{ code: '01', name: 'text' }, { code: '02', name: 'text2'}];
            page.initCombogridData('productContainer','tb',data);
            page.initCombogridData('productContainer1', 'tb1', data);
            page.initCombogridData('productContainer2', 'tb2', data);

            //page.InitBigSmallData(null);
            //page.InitEngineNoData(null);
        },
        InitBigSmallData: function (name) {
            page.post({ action: 'GetBigSmallData', data: JSON.stringify(page.para), name: name }, false, function (res) {
                if (name == null) {
                    page.initCombogridData('productContainer', 'tb', res.DBTable);
                } else {
                    $('#productContainer').combogrid('grid').datagrid('loadData', res.DBTable);
                }
            });
        },
        InitEngineNoData: function (name) {
            page.post({ action: 'getEngineNoByFactoryID', name: name }, false, function (res) {
                if (name == null) {
                    page.initCombogridData('productContainer1', 'tb1', res.DBTable);
                } else {
                    $('#productContainer1').combogrid('grid').datagrid('loadData', res.DBTable);
                }
            });
        },
        InitEngineNoData1: function (name) {
            page.post({ action: 'getEngineNoByFactoryID', name: name }, false, function (res) {
                if (name == null) {
                    page.initCombogridData('productContainer2', 'tb2', res.DBTable);
                } else {
                    $('#productContainer2').combogrid('grid').datagrid('loadData', res.DBTable);
                }
            });
        },

        initCombogridData: function (id, tid, data) {
            var columns = [];
            if (id == "productContainer") {
                columns = [{ field: 'PRODUCTID', title: 'PRODUCTID', width: 60, hidden: true },
                    { field: 'PRODUCTNAME', title: '零组件图号', width: 80 },
                    { field: 'PRODUCTDESC', title: '零组件名称', width: 80 },
                    { field: 'PRODUCTBATCHNO', title: 'ERP批次号', width: 70}];
            } else {
                columns = [{ field: 'PRODUCTID', title: 'PRODUCTID', width: 60, hidden: true },
                    { field: 'PRODUCTNAME', title: '发动机号', width: 200}];
            }
            $('#' + id).combogrid({
                panelWidth: 235,
                panelHeight: 200,
                idField: 'PRODUCTID',
                textField: 'PRODUCTDESC',
                toolbar: '#' + tid,
                data: data,
                columns: [columns],
                onSelect: function (index, row) {
                    if (id == "productContainer") {
                        $('#ProductName').textbox('setValue', row.PRODUCTNAME);
                        $('#ERPBatchNo').textbox('setValue', row.PRODUCTBATCHNO);
                    }
                }
            });
        },

        //保存 ExchangeInfoForm
        submitData: function () {
            var frdata = $('#ExchangeInfoForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            data.Source = $('#productContainer1').combobox('getText');
            data.UpExchangeCodeNo = $('#productContainer2').combobox('getText');
            if (data.ExchangeDate == "") { displayMessage("请选择日期", false); return; }
            if (data.ExchangeMethod == "" || data.ExchangeMethod == undefined) { displayMessage("请选择串件方式", false); return; }
            if (data.ProductID == "") { displayMessage("请选择零组件", false); return; }
            if (data.WorkHours == "") { displayMessage("请录入已工作时间", false); return; }
            if (data.FactoryWorkHours == "") { displayMessage("请录入厂内工作时间", false); return; }
            if (data.Qty == "") { displayMessage("请录入被串数量", false); return; }
            if (data.Reason == "") { displayMessage("请录入串件原因及措施", false); return; }
            if (data.Source == "") { displayMessage("请录入串件零、组件来源", false); return; }

            if (data.UpExchangeCodeNo == "") { displayMessage("请录入新机（品）/修理机（品）编号", false); return; }
            if (data.UpContainerNo == "") { displayMessage("请录入串上任务号", false); return; }
            if (data.UpQty == "") { displayMessage("请录入串上数量", false); return; }
            if (data.UpBatchNo == "") { displayMessage("请录入串上零组件批次号", false); return; }
            if (data.TotalWorkHours == "") { displayMessage("请录入累计工作时间/总寿命", false); return; }
            if (data.IsOverFactoryTime == "") { displayMessage("请选择是否大于被串件厂内工作时间", false); return; }
            var param = {
                action: "SaveExchangeData",
                data: JSON.stringify(data),
                para: JSON.stringify(page.para)
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    page.para.ExchangeID = res.ReturnData;
                }

                displayMessage(res.Message, res.Result);

            });
        },
        checkboxSelect: function (obj) {
            $('input[name=ExchangeMethod]').not(obj).prop('checked', false);
        },
        checkboxSelect1: function (obj) {
            $('input[name=IsOverFactoryTime]').not(obj).prop('checked', false);
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },
        //post数据
        post: function (param, async, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });



</script>
